package com.nwpu.bigdata.generator;

import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

import org.mybatis.generator.api.MyBatisGenerator;
import org.mybatis.generator.config.Configuration;
import org.mybatis.generator.config.xml.ConfigurationParser;
import org.mybatis.generator.internal.DefaultShellCallback;

/**
 * @author carlin
 * @date 2018/7/9
 */
public class Generator {
	private static final String GENERATOR_CONFIG = "/generator/generatorConfig.xml";
	private static final boolean OVER_WRITE = true;

	public static void main(String[] args) throws Exception {
		List<String> warnings = new ArrayList<String>();
		
		InputStream is = Generator.class.getResourceAsStream(GENERATOR_CONFIG);
		ConfigurationParser cp = new ConfigurationParser(warnings);
		Configuration config = cp.parseConfiguration(is);
		is.close();

		DefaultShellCallback callback = new DefaultShellCallback(OVER_WRITE);
		MyBatisGenerator myBatisGenerator = new MyBatisGenerator(config, callback, warnings);
		myBatisGenerator.generate(null);
		for (String warning : warnings) {
			System.out.println(warning);
		}
	}
}
